/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package teste.swing;

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author FastPark
 */
public class SIOThread extends Thread{

    public String name;
    public String[] processos;
    
    public SIOThread(String name, String[] processos) {
        this.name = name;
        this.processos = processos;
    }
    
    public String escalonar(String[] processos){
        Random gerador = new Random();
        int indice = gerador.nextInt(processos.length);
        return processos[indice];
    }
    
    @Override
    public void run() {
        while(true){
            System.out.println(this.name + " - "+ this.escalonar(processos));
            try {
                sleep(500);
            } catch (InterruptedException ex) {
                Logger.getLogger(SIOThread.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
    }

     
    
    public static void main(String[] args){
        
        String[] processos = {"A", "B", "C", "D", "E"};
        SIOThread t1 = new SIOThread("Escalonador 1", processos);
        t1.start();
        
        SIOThread t2 = new SIOThread("Escalonador 2", processos);
        t2.start();
    }
}
